import configparser
import json
from concurrent.futures import ThreadPoolExecutor
from queue import Queue
import pandas as pd

from UserStruct import BarData


# tushare秘钥
tushareToken = ''

broker_name = 'simnow模拟7*24小时'
investorID = '191517'
password = 'luoyu123456@'
broker_id = '9999'
market_server_front = 'tcp://218.202.237.33:10213'
trade_server_front = 'tcp://218.202.237.33:10203'
appID = 'simnow_client_test'
authcode = '0000000000000000'
productInfo_fileName = './con_file/productInfo.ini'



# 需要订阅的合约
subID = []
# 查询信号，用于检查是否查询完成，true代表正在查询
qry_flag = True
# 交易账户登录信号，用于检查是否登录成功，True代表登录成功
tdLogin_flag = False

# 下单必要元素
frontID = None  # 前置编号
sessionID = None  # 会话编号
maxOrderRef = None  # 最大报单引用

# 策略字典
strategy_map = {}
# 订单字典
order_map = {}
# # 持仓字典
# position_map = {}
# 详细持仓字典
positionDetail_map = {}

# 交易日
tradingDay = None

# 线程池
save_data_pool = ThreadPoolExecutor(5)

# 其他
tduserapi = None
tduserspi = None

mduserapi = None
mduserspi = None

ctpWang = None

# 合约交易所
ExchangeID = {}

# 合约手续费和保证金等
productInfo = configparser.ConfigParser()
productInfo.read(productInfo_fileName, encoding='utf-8')

# 读取json文件
try:
    with open('./con_file/ExchangeID.json', 'r', encoding='utf8') as f:
        ExchangeID = json.load(f)
# 如果有错误则创建文件
except Exception as e:
    print('读取ExchangeID.json失败！\n失败原因：{}\n已创建空白文件'.format(e))
    with open('./con_file/ExchangeID.json', 'w', newline='\n', encoding='utf-8') as f:
        # json.dump(ExchangeID, f, ensure_ascii=False)
        data = json.dumps(ExchangeID, indent=4, ensure_ascii=False)
        f.write(data)

# tick数据队列
tickQueue = Queue()

# 计算数据传送时间
startTime = None
endTime = None


# 需订阅的K线合约和类型
subKlineID = []
subKlineType = []

# 所有合约等当前K线字典
klineMin_map = {}

# K线数据队列
klineQueue = Queue()

# 记录资源管理器
process = None


# 保存数据时信号,如果为true则不保存新数据
save_data_flag = False

# 上传到百度云位置
baiduYunFolder = '测试'

